<?php

namespace App\Home\Controllers;

use App\Home\Filters\WorshipAlbumFilter;
use App\Home\Models\WorshipAlbum;
use App\Home\Requests\WorshipAlbumRequest;
use App\Home\Resources\WorshipAlbumResource;
use Illuminate\Http\Request;

class WorshipAlbumController extends Controller
{
    public function store(
        WorshipAlbumRequest $request, 
        WorshipAlbum $worshipAlbum
    ){
        $inputs = $request->validated();
        $worshipAlbum = $worshipAlbum->add($inputs);

        return $this->created(WorshipAlbumResource::make($worshipAlbum));
    }

    public function update(
        WorshipAlbumRequest $request, 
        WorshipAlbum $worshipAlbum
    ){
        $inputs = $request->validated();
        $worshipAlbum->update($inputs);

        return $this->created(WorshipAlbumResource::make($worshipAlbum));
    }

    public function destroy(
        WorshipAlbum $worshipAlbum
    ){
        $worshipAlbum->delete();
        return $this->noContent();
    }

    public function index(
        WorshipAlbumRequest $request,
        WorshipAlbumFilter $filter
    ){
        $fields = [
            "*",
        ];
        $worshipAlbums = WorshipAlbum::query()
            ->filter($filter)
            ->select($fields)
            ->paginate();

        return $this->ok(WorshipAlbumResource::collection($worshipAlbums));
    }

    public function show(
        Int $id
    ){
        $fields = [
            "*",
        ];
        $worshipAlbum = WorshipAlbum::query()
            ->select($fields)
            ->find($id);
        return $this->ok(WorshipAlbumResource::make($worshipAlbum));
    }
}
